package com.woniuxy.service.impl;

import com.woniuxy.service.UserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Service实现类 实现UserDetailsService接口，重写loadUserByUsername方法
 * 调用loadUserByUsername方法去数据库查询权限信息
 *
 * String s：用户的登录账号  account
 * UserDetails：返回一个UserDetails对象
 * */
@Component
public class CustomUserDetailService implements UserDetailsService {

    @Resource
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {

        // 1. 调用service，通过用户账号查询出用户的权限信息，封装为UserDetails对象，并返回
        // 2. UserDetails是一个接口，那么用findUser的User实现UserDetails接口
        return userService.getLoginUser(account);
    }
}
